package vista;

import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.Timer;

public class AutoDismiss {
    private JDialog dialog;
    
    public Timer timer = new Timer(500, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }

    });

    public AutoDismiss(Component parent, String message) {
        final JOptionPane optionPane = new JOptionPane(message, 1);
        timer.setRepeats(false);

        dialog = optionPane.createDialog(parent, message);
        dialog.setTitle("Mensaje");
        dialog.setBackground(Color.RED.brighter());
        //dialog.setOpacity((float) 0.8); //; esta linea me estaba dando error. Michael

        timer.start();
        if (dialog.isDisplayable()) {
            dialog.setVisible(true);
        }
    }

}
